package com.icesoft.xsnow.framework.config;

import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor;
import com.icesoft.xsnow.framework.config.orm.CommonFieldsAutomaticHandler;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.transaction.annotation.EnableTransactionManagement;

import javax.sql.DataSource;

/**
 * @program: xsnow
 * @description: Mybatisplus 通用配置
 * @author: xuefeng.gao
 * @create: 2019-05-15 16:43
 **/
@Configuration
@ConditionalOnBean(DataSource.class)
@ConditionalOnMissingBean(MybatisPlusAutoConfiguration.class)
@MapperScan("com.icesoft.xsnow.**.mapper")
@EnableTransactionManagement
public class MybatisPlusAutoConfiguration {
    /**
     * 分页插件
     */
    @Bean
    public PaginationInterceptor paginationInterceptor() {
        return new PaginationInterceptor();
    }
    /**
    * 公共字段填充插件
    **/
    @Bean
    public CommonFieldsAutomaticHandler metaObjectHandler(){
        return new CommonFieldsAutomaticHandler();
    }
}
